class Box { protected int L,B,H; public void setDimension(int x,int y,int z) { L=x; B=y; H=z; } public void volume() { int v=L*B*H; System.out.println("Volume is "+v); } public void surfaceArea( ) { int a=2*L*H+2*B*H+2*L*B; System.out.println("Surface Area is "+a); } } class OpenBox extends Box { public void surfaceArea() { int a=2*L*H+2*B*H+L*B; System.out.println("Surface Area is "+a); } } class demo { public static void main(String args[]) { Box a=new Box(); a.setDimension(2,2,2); a.volume(); a.surfaceArea(); OpenBox b = new OpenBox(); b.setDimension(1,1,1); b.volume(); b.surfaceArea(); } }
Volume is 8 Surface Area is 24 Volume is 1 Surface Area is 5
class Account { protected int accno; protected double balance; public void open(int an,int bl) { accno=an; balance=bl; } public void deposit(int amt) { balance=balance+amt; } public void withdraw(int amt) { balance=balance–amt; } public void showBalance() { System.out.println("AccNo is "+accno); System.out.println("Balance is "+balance); } } class CAccount extends Account { public void deposit(int amt) { balance=balance+amt; balance=balance-1; } public void withdraw(int amt) { balance = balance–amt; balance = balance–1; } } class demo { public static void main(String args[]) { Account a=new Account(); a.open(4117,25000); a.deposit(5000); a.withdraw(2000); a.showBalance(); CAccount b=new CAccount(); b.open(3012,10000); b.deposit(5000); b.withdraw(2000); b.withdraw(3000); b.showBalance(); } }
AccNo is 4117 Balance is 28000 AccNo is 3012 Balance is 9997